package com.scy.demo.controller;

import com.scy.demo.pojo.Resume;
import com.scy.demo.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author 司晨雨
 * @date 2020/6/8 22:47
 * @description
 */
@Controller
@RequestMapping("/resume")
public class ResumeController {


    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/list")
    public String list(HttpServletRequest request, HttpServletResponse response, Model model){
        List<Resume> list = resumeService.findAll();
        model.addAttribute("list", list);
        return "list";
    }

    @RequestMapping("/add")
    public String add(HttpServletRequest request, HttpServletResponse response,Model model){
        return "add";
    }

    @RequestMapping("/update")
    public String update(Model model,Long id){
        Resume resume = resumeService.getOne(id);
        model.addAttribute("resume",resume);
        return "update";
    }

    @RequestMapping("/save")
    public String save(HttpServletRequest request, HttpServletResponse response,Model model,Resume resume){
        if(resume.getId()!=null){
            resumeService.update(resume);
        }else{
            resumeService.add(resume);
        }
        return "redirect:list";
    }

    @RequestMapping("/delete")
    public String delete(HttpServletRequest request, HttpServletResponse response,Model model,Long id){
        resumeService.delete(id);
        return "redirect:list";
    }


}
